home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / osi / isode / vmsisode / vmsisode80_tar.Z / vmsisode80_tar / sockit / gccinclude / rpc / clnt.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-24  |  8.5 KB  |  333 lines

  1. /* @(#)clnt.h    1.1 87/11/04 3.9 RPCSRC */
  2. /*
  3.  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  4.  * unrestricted use provided that this legend is included on all tape
  5.  * media and as a part of the software program in whole or part.  Users
  6.  * may copy or modify Sun RPC without charge, but are not authorized
  7.  * to license or distribute it to anyone else except as part of a product or
  8.  * program developed by the user.
  9.  * 
  10.  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  11.  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  12.  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  13.  * 
  14.  * Sun RPC is provided with no support and without any obligation on the
  15.  * part of Sun Microsystems, Inc. to assist in its use, correction,
  16.  * modification or enhancement.
  17.  * 
  18.  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  19.  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  20.  * OR ANY PART THEREOF.
  21.  * 
  22.  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  23.  * or profits or other special, indirect and consequential damages, even if
  24.  * Sun has been advised of the possibility of such damages.
  25.  * 
  26.  * Sun Microsystems, Inc.
  27.  * 2550 Garcia Avenue
  28.  * Mountain View, California  94043
  29.  */
  30. /*    @(#)clnt.h 1.30 87/07/14 SMI      */
  31.  
  32. /*
  33.  * clnt.h - Client side remote procedure call interface.
  34.  *
  35.  * Copyright (C) 1984, Sun Microsystems, Inc.
  36.  */
  37.  
  38. #ifndef _CLNT_
  39. #define _CLNT_
  40.  
  41. /*
  42.  * Rpc calls return an enum clnt_stat.  This should be looked at more,
  43.  * since each implementation is required to live with this (implementation
  44.  * independent) list of errors.
  45.  */
  46. enum clnt_stat {
  47.     RPC_SUCCESS=0,            /* call succeeded */
  48.     /*
  49.      * local errors
  50.      */
  51.     RPC_CANTENCODEARGS=1,        /* can't encode arguments */
  52.     RPC_CANTDECODERES=2,        /* can't decode results */
  53.     RPC_CANTSEND=3,            /* failure in sending call */
  54.     RPC_CANTRECV=4,            /* failure in receiving result */
  55.     RPC_TIMEDOUT=5,            /* call timed out */
  56.     /*
  57.      * remote errors
  58.      */
  59.     RPC_VERSMISMATCH=6,        /* rpc versions not compatible */
  60.     RPC_AUTHERROR=7,        /* authentication error */
  61.     RPC_PROGUNAVAIL=8,        /* program not available */
  62.     RPC_PROGVERSMISMATCH=9,        /* program version mismatched */
  63.     RPC_PROCUNAVAIL=10,        /* procedure unavailable */
  64.     RPC_CANTDECODEARGS=11,        /* decode arguments error */
  65.     RPC_SYSTEMERROR=12,        /* generic "other problem" */
  66.  
  67.     /*
  68.      * callrpc & clnt_create errors
  69.      */
  70.     RPC_UNKNOWNHOST=13,        /* unknown host name */
  71.     RPC_UNKNOWNPROTO=17,        /* unkown protocol */
  72.  
  73.     /*
  74.      * _ create errors
  75.      */
  76.     RPC_PMAPFAILURE=14,        /* the pmapper failed in its call */
  77.     RPC_PROGNOTREGISTERED=15,    /* remote program is not registered */
  78.     /*
  79.      * unspecified error
  80.      */
  81.     RPC_FAILED=16
  82. };
  83.  
  84.  
  85. /*
  86.  * Error info.
  87.  */
  88. struct rpc_err {
  89.     enum clnt_stat re_status;
  90.     union {
  91.         int RE_errno;        /* realated system error */
  92.         enum auth_stat RE_why;    /* why the auth error occurred */
  93.         struct {
  94.             u_long low;    /* lowest verion supported */
  95.             u_long high;    /* highest verion supported */
  96.         } RE_vers;
  97.         struct {        /* maybe meaningful if RPC_FAILED */
  98.             long s1;
  99.             long s2;
  100.         } RE_lb;        /* life boot & debugging only */
  101.     } ru;
  102. #define    re_errno    ru.RE_errno
  103. #define    re_why        ru.RE_why
  104. #define    re_vers        ru.RE_vers
  105. #define    re_lb        ru.RE_lb
  106. };
  107.  
  108.  
  109. /*
  110.  * Client rpc handle.
  111.  * Created by individual implementations, see e.g. rpc_udp.c.
  112.  * Client is responsible for initializing auth, see e.g. auth_none.c.
  113.  */
  114. typedef struct {
  115.     AUTH    *cl_auth;            /* authenticator */
  116.     struct clnt_ops {
  117.         enum clnt_stat    (*cl_call)();    /* call remote procedure */
  118.         void        (*cl_abort)();    /* abort a call */
  119.         void        (*cl_geterr)();    /* get specific error code */
  120.         bool_t        (*cl_freeres)(); /* frees results */
  121.         void        (*cl_destroy)();/* destroy this structure */
  122.         bool_t          (*cl_control)();/* the ioctl() of rpc */
  123.     } *cl_ops;
  124.     caddr_t            cl_private;    /* private stuff */
  125. } CLIENT;
  126.  
  127.  
  128. /*
  129.  * client side rpc interface ops
  130.  *
  131.  * Parameter types are:
  132.  *
  133.  */
  134.  
  135. /*
  136.  * enum clnt_stat
  137.  * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
  138.  *     CLIENT *rh;
  139.  *    u_long proc;
  140.  *    xdrproc_t xargs;
  141.  *    caddr_t argsp;
  142.  *    xdrproc_t xres;
  143.  *    caddr_t resp;
  144.  *    struct timeval timeout;
  145.  */
  146. #define    CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs)    \
  147.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  148. #define    clnt_call(rh, proc, xargs, argsp, xres, resp, secs)    \
  149.     ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs))
  150.  
  151. /*
  152.  * void
  153.  * CLNT_ABORT(rh);
  154.  *     CLIENT *rh;
  155.  */
  156. #define    CLNT_ABORT(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  157. #define    clnt_abort(rh)    ((*(rh)->cl_ops->cl_abort)(rh))
  158.  
  159. /*
  160.  * struct rpc_err
  161.  * CLNT_GETERR(rh);
  162.  *     CLIENT *rh;
  163.  */
  164. #define    CLNT_GETERR(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  165. #define    clnt_geterr(rh,errp)    ((*(rh)->cl_ops->cl_geterr)(rh, errp))
  166.  
  167.  
  168. /*
  169.  * bool_t
  170.  * CLNT_FREERES(rh, xres, resp);
  171.  *     CLIENT *rh;
  172.  *    xdrproc_t xres;
  173.  *    caddr_t resp;
  174.  */
  175. #define    CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  176. #define    clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
  177.  
  178. /*
  179.  * bool_t
  180.  * CLNT_CONTROL(cl, request, info)
  181.  *      CLIENT *cl;
  182.  *      u_int request;
  183.  *      char *info;
  184.  */
  185. #define    CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  186. #define    clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
  187.  
  188. /*
  189.  * control operations that apply to both udp and tcp transports
  190.  */
  191. #define CLSET_TIMEOUT       1   /* set timeout (timeval) */
  192. #define CLGET_TIMEOUT       2   /* get timeout (timeval) */
  193. #define CLGET_SERVER_ADDR   3   /* get server's address (sockaddr) */
  194. /*
  195.  * udp only control operations
  196.  */
  197. #define CLSET_RETRY_TIMEOUT 4   /* set retry timeout (timeval) */
  198. #define CLGET_RETRY_TIMEOUT 5   /* get retry timeout (timeval) */
  199.  
  200. /*
  201.  * void
  202.  * CLNT_DESTROY(rh);
  203.  *     CLIENT *rh;
  204.  */
  205. #define    CLNT_DESTROY(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  206. #define    clnt_destroy(rh)    ((*(rh)->cl_ops->cl_destroy)(rh))
  207.  
  208.  
  209. /*
  210.  * RPCTEST is a test program which is accessable on every rpc
  211.  * transport/port.  It is used for testing, performance evaluation,
  212.  * and network administration.
  213.  */
  214.  
  215. #define RPCTEST_PROGRAM        ((u_long)1)
  216. #define RPCTEST_VERSION        ((u_long)1)
  217. #define RPCTEST_NULL_PROC    ((u_long)2)
  218. #define RPCTEST_NULL_BATCH_PROC    ((u_long)3)
  219.  
  220. /*
  221.  * By convention, procedure 0 takes null arguments and returns them
  222.  */
  223.  
  224. #define NULLPROC ((u_long)0)
  225.  
  226. /*
  227.  * Below are the client handle creation routines for the various
  228.  * implementations of client side rpc.  They can return NULL if a 
  229.  * creation failure occurs.
  230.  */
  231.  
  232. /*
  233.  * Memory based rpc (for speed check and testing)
  234.  * CLIENT *
  235.  * clntraw_create(prog, vers)
  236.  *    u_long prog;
  237.  *    u_long vers;
  238.  */
  239. extern CLIENT *clntraw_create();
  240.  
  241.  
  242. /*
  243.  * Generic client creation routine. Supported protocols are "udp" and "tcp"
  244.  */
  245. extern CLIENT *
  246. clnt_create(/*host, prog, vers, prot*/); /*
  247.     char *host;     -- hostname
  248.     u_long prog;    -- program number
  249.     u_long vers;    -- version number
  250.     char *prot;    -- protocol
  251. */
  252.  
  253.     
  254.     
  255.  
  256. /*
  257.  * TCP based rpc
  258.  * CLIENT *
  259.  * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
  260.  *    struct sockaddr_in *raddr;
  261.  *    u_long prog;
  262.  *    u_long version;
  263.  *    register int *sockp;
  264.  *    u_int sendsz;
  265.  *    u_int recvsz;
  266.  */
  267. extern CLIENT *clnttcp_create();
  268.  
  269. /*
  270.  * UDP based rpc.
  271.  * CLIENT *
  272.  * clntudp_create(raddr, program, version, wait, sockp)
  273.  *    struct sockaddr_in *raddr;
  274.  *    u_long program;
  275.  *    u_long version;
  276.  *    struct timeval wait;
  277.  *    int *sockp;
  278.  *
  279.  * Same as above, but you specify max packet sizes.
  280.  * CLIENT *
  281.  * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
  282.  *    struct sockaddr_in *raddr;
  283.  *    u_long program;
  284.  *    u_long version;
  285.  *    struct timeval wait;
  286.  *    int *sockp;
  287.  *    u_int sendsz;
  288.  *    u_int recvsz;
  289.  */
  290. extern CLIENT *clntudp_create();
  291. extern CLIENT *clntudp_bufcreate();
  292.  
  293. /*
  294.  * Print why creation failed
  295.  */
  296. void clnt_pcreateerror(/* char *msg */);    /* stderr */
  297. char *clnt_spcreateerror(/* char *msg */);    /* string */
  298.  
  299. /*
  300.  * Like clnt_perror(), but is more verbose in its output
  301.  */ 
  302. void clnt_perrno(/* enum clnt_stat num */);    /* stderr */
  303.  
  304. /*
  305.  * Print an English error message, given the client error code
  306.  */
  307. void clnt_perror(/* CLIENT *clnt, char *msg */);     /* stderr */
  308. char *clnt_sperror(/* CLIENT *clnt, char *msg */);    /* string */
  309.  
  310. /* 
  311.  * If a creation fails, the following allows the user to figure out why.
  312.  */
  313. struct rpc_createerr {
  314.     enum clnt_stat cf_stat;
  315.     struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
  316. };
  317.  
  318. extern struct rpc_createerr rpc_createerr;
  319.  
  320.  
  321.  
  322. /*
  323.  * Copy error message to buffer.
  324.  */
  325. char *clnt_sperrno(/* enum clnt_stat num */);    /* string */
  326.  
  327.  
  328.  
  329. #define UDPMSGSIZE    8800    /* rpc imposed limit on udp msg size */
  330. #define RPCSMALLMSGSIZE    400    /* a more reasonable packet size */
  331.  
  332. #endif /*!_CLNT_*/
  333.